#include <iostream>
#include <string>
#include <cstring>
#include <vector>
using namespace std;

class Solution
{
public:
	struct SubStr
	{
		const char* head;
		size_t len;
		const char* spos;
	};
	bool isMatch(const char *s, const char *p) 
	{
		// Start typing your C/C++ solution below
		// DO NOT write int main() function
		if(!p)
			return !s;

		if(!s)
			return !p;

		size_t plen = strlen(p);
		size_t slen = strlen(s);
		if(plen==0)
			return slen==0;
		const char *cur = p, *last = NULL;
		vector<SubStr> substrs;		
		SubStr stmp;
		do
		{
			if(*cur=='*' || !(*cur))
			{
				last = last?(last+1):p;
				if(cur!=last)
				{
					stmp.head = last;
					stmp.len = cur-last;
					substrs.push_back(stmp);
				}
				last = cur;
			}
		}while(*cur++);


		const char* curH = s;
		size_t idx = 0;
		while(*curH && (idx<substrs.size()))
		{
			SubStr& substr = substrs[idx];
			findInString(substr,curH);
			if(substr.spos)
			{
				if(idx==0 && *p!='*' && substr.spos!=s)
					return false;
				else if(idx==(substrs.size()-1) && p[plen-1]!='*' && substr.spos[substr.len])
				{
					curH = substr.spos + 1;
					continue;
				}
				idx++;
				curH = substr.spos + substr.len;
			}
			else
			{
				if(idx==0)
					return false;
				idx--;
				curH = substrs[idx].spos + 1;				
			}
		}

		return idx==substrs.size();
		
	}
private:
	void findInString(SubStr& ss,const char* s)
	{
		ss.spos = NULL;
		while(*s)
		{
			const char* curh = s;
			size_t i = 0;
			for(;i<ss.len;i++)
			{
				if(!(curh[i]))
					return;
				
				if(ss.head[i]!='?' && ss.head[i]!=curh[i])
					break;
			}
			if(i==ss.len)
			{
				ss.spos = s;
				return;
			}			
			s++;
		}
	}
};


int main()
{
	string s,p;
	Solution sol;
	while(getline(cin,s))
	{
		if(s=="")
			break;

		getline(cin,p);
		cout<<sol.isMatch(s.c_str(),p.c_str())<<endl;
	}
}